package pers.twf.twfRpc.protocol;

import lombok.Getter;

/**
 * 协议消息的状态枚举
 */
@Getter
public enum ProtocolMessageStatusEnum {
    
    OK("ok",20),
    BAD_REQUEST("badRequest",40),
    BAD_RESPONSE("badResponse",50);
    
    private final String text;
    
    private final int status;


    ProtocolMessageStatusEnum(String text, int status) {
        this.text = text;
        this.status = status;
    }

    /**
     * 根据状态码获取枚举
     * @param status
     * @return
     */
    public static ProtocolMessageStatusEnum getEnumByStatus(int status) {
        for (ProtocolMessageStatusEnum statusEnum : ProtocolMessageStatusEnum.values()) {
            if (statusEnum.status == status) {
                return statusEnum;
            }
        }
        return null;
    }
}